package com.sunhao.application;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private View content;
    private CheckBox ck_custom;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//        content = findViewById(R.id.v_content);

        findViewById(R.id.btn_rect).setOnClickListener(this);
        findViewById(R.id.btn_oval).setOnClickListener(this);
        ck_custom = findViewById(R.id.ck_custom);





//        为content设置圆角矩形
//        content.setBackgroundResource(R.drawable.shape_rect_gold);



        RadioGroup group = findViewById(R.id.radiogroup);
        group.check(R.id.female);
        group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.male:

                        break;
                    case R.id.female:

                        break;

                }
            }
        });


        //勾选触发事件
        ck_custom.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                String desc = String.format("您%s这个CheckBox", isChecked ? "勾选" : "未勾选");
                ck_custom.setText(desc);
            }
        });



    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.btn_rect:
                content.setBackgroundResource(R.drawable.shape_rect_gold);
                break;

            case R.id.btn_oval:
                content.setBackgroundResource(R.drawable.shape_oval_rose);
                break;
        }
    }
}